﻿@{
    long userId = ViewData.Get<long>("userId", 0);
    string userName = ViewData.Get("userName", string.Empty);
}
<div class="tnc-dailog-pd">
    <div class="tn-form tnc-label-short">
        <div class="tn-form-row">
            <label class="tn-form-label">
                您正在为@(userName)重置密码</label>
        </div>
        <div class="tn-form-row">
            <label class="tn-form-label">
                密码</label>
            <input type="password" name="password" id="password" class="tnui-validate tn-textbox tn-border-gray  tn-input-medium" value="" />
        </div>
        <div class="tn-form-row">
            <label class="tn-form-label">
                确认</label>
            <input type="password" name="confirmPassword" id="confirmPassword" class="tnui-validate tn-textbox tn-border-gray  tn-input-medium" value="" />
        </div>
        <div class="tn-form-row error-msg">
        </div>
    </div>
</div>
<div class="tnc-artdilog-btn tn-bg-gray tn-border-gray tn-border-top">
    @Html.Button("确认", ButtonTypes.Button, HighlightStyles.Primary, htmlAttributes: new { id = "resetPassword" })
    @Html.Button("取消", ButtonTypes.Cancel, HighlightStyles.Secondary, htmlAttributes: new { dialogOperation = "close" })
</div>
<script type="text/dialog">
this.title("重置密码");
</script>
<script type="text/javascript">
    $(document).ready(function () {
        

        $(".tnui-validate").focus(function () {
            $(".error-msg").children().remove();
        });

        $(".tnui-validate").blur(function () {
            var password = $("#password").val();
            var confirmPassword = $("#confirmPassword").val();
            showError(password, confirmPassword);
        });
        function showError(password, confirmPassword) {
            if (password == "") {
                $("div.error-msg").html("<span class='field-validation-error'>请输入密码！</span>");
                return false;
            }
            if (confirmPassword == "") {
                $("div.error-msg").html("<span class='field-validation-error'>请输入确认密码！</span>");
                return false;
            }
            if (password != confirmPassword) {
                $("div.error-msg").html("<span class='field-validation-error'>两次输入不一致！</span>");
                return false;
            }
        }

        $("#resetPassword").click(function (e) {
            e.preventDefault();
            var password = $("#password").val();
            var confirmPassword = $("#confirmPassword").val();
            showError(password, confirmPassword);
            if ($(".error-msg").children().length) {
                return false;
            }
            var userId = "@userId";
            var url = "@SiteUrls.Instance()._ResetUserPassword()";
            $.post(url, "password=" + $("#password").val() + "&userId=" + userId, function (data) {
                art.dialog.tips(data.MessageContent, 1.5, data.MessageType, function () {
                    window.location.reload();
                });
            });
        });
    });
</script>
